package com.pointstar.dp.modules.project.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pointstar.dp.common.annotation.SysLog;
import com.pointstar.dp.modules.sys.controller.AbstractController;
import com.pointstar.dp.common.entity.Page;
import com.pointstar.dp.common.entity.R;
import com.pointstar.dp.modules.project.entity.ProductEntity;
import com.pointstar.dp.modules.project.service.ProductService;

/**
 * 商品表
 * @author Korey<m13057531285@163.com>
 */
@RestController
@RequestMapping("/product")
public class ProductController extends AbstractController {
	
	private final ProductService productService;

	@Autowired
	public ProductController(ProductService productService) {
		this.productService = productService;
	}

	/**
	 * 列表
	 * @param params
	 * @return
	 */
	@PostMapping("/list")
	public Page<ProductEntity> list(@RequestBody Map<String, Object> params) {
		return productService.listProduct(params);
	}

	/**
	 * 列表
	 * @return 商品列表
	 */
	@GetMapping("/listNoPage")
	public List<ProductEntity> listNoPage() {
		return productService.listProductNoPage();
	}
		
	/**
	 * 新增
	 * @param product
	 * @return
	 */
	@SysLog("新增商品表")
	@PostMapping("/save")
	public R save(@RequestBody ProductEntity product) {
		return productService.saveProduct(product);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@PostMapping("/info")
	public R getById(@RequestBody Integer id) {
		return productService.getProductById(id);
	}
	
	/**
	 * 修改
	 * @param product
	 * @return
	 */
	@SysLog("修改商品表")
	@PostMapping("/update")
	public R update(@RequestBody ProductEntity product) {
		return productService.updateProduct(product);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除商品表")
	@PostMapping("/remove")
	public R batchRemove(@RequestBody Integer[] id) {
		return productService.batchRemove(id);
	}
	
}
